#!/bin/sh
# postinst script for fdb-sql-layer

set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <postinst> `abort-remove'
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

USER_NAME=foundationdb
GROUP_NAME=$USER_NAME

LIB_DIR=/var/lib/$USER_NAME
LOG_DIR=/var/log/$USER_NAME
ETC_DIR=/etc/$USER_NAME

case "$1" in
    configure)
        if [ "$2" = "" ]; then
            getent group $GROUP_NAME >/dev/null || addgroup --system $GROUP_NAME
            getent passwd $USER_NAME >/dev/null || adduser --system --disabled-login --ingroup $GROUP_NAME --no-create-home --home $LIB_DIR --gecos "FoundationDB" --shell /bin/false $USER_NAME

            chown -R $USER_NAME:$GROUP_NAME $LIB_DIR $LOG_DIR
            chmod -R 0700 /var/log/$USER_NAME
        fi

        chown -R $USER_NAME:$GROUP_NAME $ETC_DIR
        invoke-rc.d fdb-sql-layer start

        if [ "$2" = "" ]; then
            update-rc.d fdb-sql-layer defaults
        fi
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#
